<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
  <meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="icon" href="<%=path%>/images/favicon.ico" type="image/ico">
<meta name="author" content="guowenjie">
<link href="<%=path%>/css/bootstrap.min.css" rel="stylesheet">
<link href="<%=path%>/css/materialdesignicons.min.css" rel="stylesheet">
<link href="<%=path%>/css/style.min.css" rel="stylesheet">
<link rel="stylesheet" href="<%=path%>/js/ion-rangeslider/ion.rangeSlider.min.css">
<link href="<%=path%>/js/jconfirm/jquery-confirm.min.css" rel="stylesheet">
<link href="<%=path%>/js/bootstrap-datepicker/bootstrap-datepicker3.min.css" rel="stylesheet">
<link href="<%=path%>/js/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
<link href="<%=path%>/css/materialdesignicons.min.css" rel="stylesheet">
<link rel="stylesheet" href="<%=path%>/style/layui/css/layui.css">

<script type="text/javascript" src="<%=path%>/js/jquery.min.js"></script>
 <script type="text/javascript" src="<%=path%>/js/main.min.js"></script>
<script src="<%=path%>/js/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
<script src="<%=path%>/js/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
<script type="text/javascript" src="<%=path%>/js/bootstrap.min.js"></script>
<script type="text/javascript" src="<%=path%>/js/bootstrap-table/bootstrap-table.js"></script>
<script type="text/javascript" src="<%=path%>/js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
<script type="text/javascript" src="<%=path%>/js/jconfirm/jquery-confirm.min.js"></script>
<script type="text/javascript" src="<%=path%>/style/layui/layui.js"></script>

</head>
 <div class="container-fluid p-t-15">
    
        <div  class="card">
        <div class="card-header"><h4><a style="color:#33cabb" href="<%=path%>/bg/jcsgl">决策树管理</a><a style="color:#33cabb" href="<%=path%>/bg/jcsglmx?Mname=<s:property value="Mname"/>&DMid=<s:property value="DMid"/>" >/<s:property value="Mname"/></a><a style="color:#33cabb">/新增</a></h4></div>
       <div class="card-body">
        <div class="row" id="wtdiv" >
        <div class="input-group">
                  <input type="text" class="form-control" id="title" readonly aria-label="请选择问题">
                  <div class="input-group-btn" >
                     <button type="button" id="xzan" class="btn btn-default" data-toggle="modal" data-target="#choosewt">选择</button>
                  </div>
         </div>
         <br>
         <div class="form-group" id="radios" style="display:none">
          <label class="lyear-radio">
              <input type="radio" name="r1">
              <span>默认单选框</span>
            </label>
            <label class="lyear-radio radio-grey m-t-10">
              <input type="radio" name="r1">
              <span>灰色单选框</span>
            </label>
            <label class="lyear-radio radio-primary m-t-10">
              <input type="radio" checked="" name="r1">
              <span>主色单选框</span>
            </label>
            <label class="lyear-radio m-t-10">
              <input type="radio" disabled="" name="r1">
              <span>禁用的</span>
            </label>
           
           </div>
          
            
          <div class="form-group">
          <div class="example-box" id="buttons1"  style="display:none">
                <button class="btn btn-w-md btn-round btn-primary" onclick="nextwt()">下一题</button>
                <button class="btn btn-w-md btn-round btn-success" onclick="endwt()" >结束</button>
                </div> 
          </div>
          <div class="form-group">
          <div class="example-box" id="buttons2"  style="display:none">
                <button class="btn btn-w-md btn-round btn-yellow" onclick="sygwt()">上一题</button>
                 <button class="btn btn-w-md btn-round btn-primary" onclick="nextwt()">下一题</button>
                <button class="btn btn-w-md btn-round btn-success" onclick="endwt()">结束</button>
                </div> 
          </div>
          </div>
          
           <div class="row" id="jsdiv" style="display:none">
           <div class="form-group col-md-12">
              <label for="Pdjl">判断结论</label>
              <input type="text" class="form-control" id="Pdjl"  value=""  />
            </div>
           <div class="form-group col-md-12">
              <label for="seo_description">判断依据</label>
              <textarea class="form-control" id="Pdyj"  rows="5" value="" ></textarea>
            </div>
            <div class="form-group col-md-12">
              <label for="seo_description">研究内容</label>
              <textarea class="form-control" id="Yjnr"  rows="5" value="" ></textarea>
            </div>
           <div class="example-box">
                <button class="btn btn-w-md btn-round btn-success" onclick="savejcs()">保存</button>
                </div> 
          </div>
        </div>
      </div></div>
      <div class="modal fade bs-example-modal-lg" tabindex="-1" id="choosewt" role="dialog" data-backdrop="static" data-keyboard="false" aria-labelledby="myModalLabel">
            <div class="modal-dialog modal-lg" role="document">
              <div class="modal-content">
                <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                  <h4 class="modal-title" id="myModalLabel">问题清单</h4>
                </div>
                <div class="modal-body">
               <form id="form1"> 
               <div id="toolbar" class="toolbar-btn-action">
           <button  type="button" class="btn btn-success" onclick="xzwt();"><span class="mdi mdi-comment-check" aria-hidden="true"></span>确定</button>       
           </div>
                <table id="table" ></table>
                 </form>
                </div>
              </div>
            </div>
          </div>
  
      
   
      
       <script type="text/javascript">
  
       
       
       var DMid = "<s:property value="DMid"/>";
       var Mname = "<s:property value="Mname"/>";
       var Wtid = "<s:property value="Wtid"/>";
       
       var Wtdaids = new Array();
       var tmsl = 0;
       
       if(Wtid == 0){
    	   document.getElementById("xzan").disabled = false; 
       }else{
    	   document.getElementById("xzan").disabled = true; 
    	   $("#title").val("<s:property value="wtxx.Wtname"/>"); 
    	   $.ajax({
    	 		type: "post",//方法类型
    	 	   dataType: "json",//预期服务器返回的数据类型 jsonp跨域
    	 		url: "<%=path%>/bg/getwtdadata",
    	 		data:{
    	 			"wtxx.Wtid":Wtid
    	 		},
    	 		success: function(req) {	
    	 			let data = req.data;
    	 			$('#radios')[0].innerHTML = "";
    	 			let radhtml = "";
    	 			for(var a=0;a<data.length;a++){
    	 				radhtml = radhtml+'<label class="lyear-radio radio-primary"><input type="radio" value="'+data[a].Wtdaid+'" onclick="buttonshow('+data[a].Wtdaid+',this);" name="r1">';
    	 				radhtml = radhtml+'<span>'+data[a].Daname+'</span></label>';
    	 			}
    	 			$('#radios')[0].innerHTML = radhtml;
    	 			
    	 			document.getElementById("radios").style.display ="block";
    	 				
    	 		},error: function(e){ 
    	 			console.log(e);
    	 			
    	 		}
    	 	});
       }
       
       $('#table').bootstrapTable({
    	   classes: 'table table-condensed table-hover',
    		data:[],
    		toolbar: '#toolbar',       // 工具按钮容器	
    	    dataType : 'json',        // 因为本示例中是跨域的调用,所以涉及到ajax都采用jsonp,
    	    pagination: true,                    // 是否显示分页
    	    search: true,                    // 是否显示分页
    	    singleSelect: true,//单行选择单行,设置为true将禁止多选
     	    pageNumber: 1,                       // 初始化加载第一页，默认第一页
    	    pageSize: 10,                        // 每页的记录行数
    	    sidePagination: "client",            // 分页方式：client客户端分页，server服务端分页
    	    columns: [{
    	    	checkbox: true    // 是否显示复选框
  		     },{
    	        field: 'Wtid',
    	        title: '题目序号',
    	        width:80
    	        
    	    },{
    	        field: 'WtBZ',
    	        title: '题目说明',
    	    },{
    	        field: 'Wtname',
    	        title: '题目',
    	    }],
    	 
    	    onLoadSuccess: function(data){
    	        $("[data-toggle='tooltip']").tooltip();
    	    }
    	});
    	
       search();
   	function search(){
   	$.ajax({
   		 type: "post",//方法类型
   	   dataType: "json",//预期服务器返回的数据类型 jsonp跨域
   		url: "<%=path%>/bg/gettkdata",
   		success: function(req) {	
   			let data = req.data;
   			$("#table").bootstrapTable('refreshOptions',{data:data});	 
   		},error: function(e){ 
   			console.log(e);
   			
   		}
   	});
   	}
   	
   	
   	function xzwt(){
   		let row = $("#table").bootstrapTable('getSelections');     
   	  if(row.length==0){
   		 $('#choosewt').modal('hide');  
   		}else{
   		$("#title").val(row[0].Wtname);  
   		$('#choosewt').modal('hide');  
   	    search();
   	    
   	 $.ajax({
 		type: "post",//方法类型
 	   dataType: "json",//预期服务器返回的数据类型 jsonp跨域
 		url: "<%=path%>/bg/getwtdadata",
 		data:{
 			"wtxx.Wtid":row[0].Wtid
 		},
 		success: function(req) {	
 			let data = req.data;
 			$('#radios')[0].innerHTML = "";
 			let radhtml = "";
 			for(var a=0;a<data.length;a++){
 				radhtml = radhtml+'<label class="lyear-radio radio-primary"><input type="radio" value="'+data[a].Wtdaid+'" onclick="buttonshow('+data[a].Wtdaid+',this);" name="r1">';
 				radhtml = radhtml+'<span>'+data[a].Daname+'</span></label>';
 			}
 			$('#radios')[0].innerHTML = radhtml;
 			
 			document.getElementById("radios").style.display ="block";
 				
 		},error: function(e){ 
 			console.log(e);
 			
 		}
 	});
   	    
   	    
   	    
   	    
   	  }
   		
   	}
   	
   	var czWtdaid = "";
   	function buttonshow(id,obj){
   		
   		if(tmsl==0){
   			document.getElementById("buttons1").style.display ="block";	
   			document.getElementById("buttons2").style.display ="none";	
   	   		}else{
   			document.getElementById("buttons2").style.display ="block";
   			document.getElementById("buttons1").style.display ="none";	
   		}
   		
   	}
   	var m = new Map(); // 空Map
   	var sygid = 0;
   	function nextwt(){
   		document.getElementById("xzan").disabled = false; 
   		var val=$('input:radio[name="r1"]:checked').val();
   		if(val){
   		tmsl = tmsl + 1; 
   		sygid = val;
   		Wtdaids.push(val);
   		let xx = new Array();
   		xx.title = $("#title").val(); 
   		xx.innerHTML = $('#radios')[0].innerHTML; 
   		m.set(val,xx); // 添加新的key-value
   		document.getElementById("radios").style.display ="none";
   		document.getElementById("buttons1").style.display ="none";
   		document.getElementById("buttons2").style.display ="none";
   		$("#title").val("");  
   		
   		}else{
   		 $.alert("请选择内容");	
   		}
    }
   	
	function sygwt(){
	let xx = m.get(sygid);
	tmsl = tmsl - 1; 
	document.getElementById("radios").style.display ="none";
	document.getElementById("buttons1").style.display ="none";
	document.getElementById("buttons2").style.display ="none";
	$("#title").val(xx.title); 
	$('#radios')[0].innerHTML = xx.innerHTML;
	
	let val=$('input:radio[name="r1"]');
	for(var i=0;i<val.length;i++){
		if(val[i].value==sygid){
			val[i].checked = true;
		}
	}
	document.getElementById("radios").style.display ="block";
	if(tmsl==0){
			document.getElementById("buttons1").style.display ="block";	
			document.getElementById("buttons2").style.display ="none";	
	   		}else{
			document.getElementById("buttons2").style.display ="block";
			document.getElementById("buttons1").style.display ="none";	
		}	
	m.delete(sygid);
	let index = Wtdaids.indexOf(sygid);
	Wtdaids.splice(index, 1);
	sygid = Wtdaids[Wtdaids.length-1]
	if(Wtdaids.length==0){
		if(Wtid == 0){
	    	   document.getElementById("xzan").disabled = false; 
	       }else{
	    	   document.getElementById("xzan").disabled = true; 
	    	   }
	}
	//console.log(sygid);
	}
	
	function endwt(){
		var val=$('input:radio[name="r1"]:checked').val();
   		if(val){
   		tmsl = tmsl + 1; 
   		sygid = val;
   		Wtdaids.push(val);
   		let xx = new Array();
   		xx.title = $("#title").val(); 
   		xx.innerHTML = $('#radios')[0].innerHTML; 
   		m.set(val,xx); // 添加新的key-value
   		document.getElementById("radios").style.display ="none";
   		document.getElementById("buttons1").style.display ="none";
   		document.getElementById("buttons2").style.display ="none";
   		document.getElementById("wtdiv").style.display ="none";
   		document.getElementById("jsdiv").style.display ="block";
   		$("#title").val("");  
   		}else{
   		 $.alert("请选择内容");	
   		}
		
		
	}
	
	function savejcs(){
		let Pdyj = $("#Pdyj").val();  
		let Pdjl = $("#Pdjl").val();  
		let Yjnr = $("#Yjnr").val();  
		console.log(Pdyj,Pdjl,Yjnr);
		if(Pdyj==""||Pdjl==""||Yjnr==""){
 		   $.alert("请填写完整数据"); 
 	   }else{
		
 		  $.ajax({
              //几个参数需要注意一下
                  type: "POST",//方法类型
                  dataType: "json",//预期服务器返回的数据类型
                  url: "<%=path%>/bg/savejcs" ,//url
                  data: {
               	 "jcs.Pdyj":Pdyj,
               	 "jcs.Pdjl":Pdjl,
               	 "jcs.Yjnr":Yjnr,
               	 "jcs.Wtdaids":Wtdaids.join(","),
               	 "jcs.DMid":DMid
               	  },
                  success: function (result) {
               	   
                	  if(result.msg=="success"){
                		
                		  window.location = "<%=path%>/bg/jcsglmx?Mname="+Mname+"&DMid="+DMid;
                		  
                	  }else{
                		  $.alert(result.msg);  
                		  
                	  }
               	  
                  },
                  error : function(e) {
                	  $.alert("数据异常，保存失败");  
                    console.log(e);
                  }
              }); 
 	   }
	}
	
	
      </script>
       </body>

</html>   